get 请求中如何携带 body 参数 |
您所在的位置:网站首页 › 请求接口是 在body添加参数中吗 › get 请求中如何携带 body 参数 |
先说结果, 浏览器中不能带. https://github.com/axios/axios/issues/787 fetch fetch("/users", { method: "GET", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: "Hubot", login: "hubot" }) });得到报错: Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body. 具有 GET/HEAD 方法的请求不能有 body. xhr var a = new XMLHttpRequest(); a.open("GET", "/"); a.send("testBody");xhr 没有成功发送 testBody 参数. 总结浏览器当前的实现是不允许 get 发送 body, 但后端应用通常可以发送. 比如 nodejs 或 postman . 所以, 如果是自己的程序. 最好按规范来,不要在 get 里传 body, 如果是第三方API, 无法更改, 那么可以用后端服务转发一下. 因为前端不能使用 get 方法从浏览器里发送 body. |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |